import { isAuth } from '@/util/auth'
import React from 'react'

/*
route list some => permissions
      return children : null
      <AccessControl permissions={['1', '6']}>内容</AccessControl>
*/
const AccessControl: React.FC<{ permissions: string[]; children: React.ReactNode }> = ({ permissions, children }) => {
  if (!Array.isArray(permissions)) {
    throw new Error('Permissions must be an array.')
  }
  return isAuth(permissions) ? children : null
}

export default AccessControl
